package org.jeecg.modules.jindie.controller;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.query.QueryGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.jeecg.modules.jindie.entity.CustomerEntity;
import org.jeecg.modules.jindie.service.TBdCustomerService;


import javax.servlet.http.HttpServletRequest;


/**
 * ${comments}
 *
 * @author gaoshaowen
 * @email gaoshaowen@topwisesz.com
 * @date 2024-12-20 14:54:39
 */
@RestController
@RequestMapping("jindie/customer")
@Api(tags="金蝶客户表")
public class TBdCustomerController {
    @Autowired
    private TBdCustomerService tBdCustomerService;


    /**
     * 分页列表查询
     *
     * @param customerEntity
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "合同审批表-分页列表查询")
    @ApiOperation(value="客户-分页查询", notes="客户-分页列表查询")
    @GetMapping(value = "/list")
    public Result<IPage<CustomerEntity>> queryPageList(CustomerEntity customerEntity,
                                                       @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                       @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                                       HttpServletRequest req) {
        QueryWrapper<CustomerEntity> queryWrapper = QueryGenerator.initQueryWrapper(customerEntity, req.getParameterMap());
        Page<CustomerEntity> page = new Page<CustomerEntity>(pageNo, pageSize);
        IPage<CustomerEntity> pageList = tBdCustomerService.page2(page, queryWrapper);
        return Result.OK(pageList);
    }

    /**
     * 列表查询
     *
     * @param customerEntity
     * @param req
     * @return
     */
    //@AutoLog(value = "客户-列表查询")
    @ApiOperation(value="客户-所有查询", notes="客户-所有查询")
    @GetMapping(value = "/listAll")
    public Result<List<CustomerEntity>> queryPageList(CustomerEntity customerEntity, HttpServletRequest req) {

        QueryWrapper<CustomerEntity> queryWrapper = QueryGenerator.initQueryWrapper(customerEntity, req.getParameterMap());

        List<CustomerEntity> list = tBdCustomerService.list2(queryWrapper);

        return Result.OK(list);
    }


    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    //@AutoLog(value = "客户-通过id查询")
    @ApiOperation(value="客户-通过id查询", notes="客户-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<CustomerEntity> queryById(@RequestParam(name="id",required=true) String id) {
        CustomerEntity comApprovalList = tBdCustomerService.getById2(id);
        if(comApprovalList==null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(comApprovalList);
    }


    @AutoLog(value = "客户-添加")
    @ApiOperation(value="客户-添加", notes="客户-添加")
    //@RequiresPermissions("org.jeecg.modules.demo:com_approval_list:add")
    @PostMapping(value = "/add")
    public Result<String> add(@RequestBody CustomerEntity customerEntity) {
        tBdCustomerService.save(customerEntity);
        return Result.OK("添加成功！");
    }


    /**
     *  编辑
     *
     * @param customerEntity
     * @return
     */
    @AutoLog(value = "客户-编辑")
    @ApiOperation(value="客户-编辑", notes="客户-编辑")
    //@RequiresPermissions("org.jeecg.modules.demo:com_approval_list:edit")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
    public Result<String> edit(@RequestBody CustomerEntity customerEntity) {
        tBdCustomerService.updateById(customerEntity);
        return Result.OK("编辑成功!");
    }

    @AutoLog(value = "客户-通过id删除")
    @ApiOperation(value="客户-通过id删除", notes="客户-通过id删除")
    //@RequiresPermissions("org.jeecg.modules.demo:com_approval_list:delete")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam(name="id",required=true) String id) {
        tBdCustomerService.removeById(id);
        return Result.OK("删除成功!");
    }


}
